<?php

namespace App\Observers\Trip\Business;

use App\Models\Trip\OrderBusiness\BusinessOrderSnMap;
use Illuminate\Support\Facades\Cache;

class BusinessOrderSnMapObserver
{
    const MAX_CACHE_DAY = 15;

    /**
     * Handle the User "created" event.
     *
     * @param BusinessOrderSnMap $map
     *
     * @return void
     */
    public function created(BusinessOrderSnMap $map)
    {
        $cache_key = "Business:OrderSn:Map:{$map->getOrderSn()}:{$map->getTradeNo()}:{$map->getBusiness()}";
        Cache::put($cache_key, $map, config('trip.ttl.day') * self::MAX_CACHE_DAY);
    }

    /**
     * Handle the User "updated" event.
     *
     * @param BusinessOrderSnMap $map
     *
     * @return void
     */
    public function updated(BusinessOrderSnMap $map)
    {
        $cache_key = "Business:OrderSn:Map:{$map->getOrderSn()}:{$map->getTradeNo()}:{$map->getBusiness()}";
        Cache::put($cache_key, $map, config('trip.ttl.day') * self::MAX_CACHE_DAY);
    }

    public function saved(BusinessOrderSnMap $map)
    {
        $cache_key = "Business:OrderSn:Map:{$map->getOrderSn()}:{$map->getTradeNo()}:{$map->getBusiness()}";
        Cache::put($cache_key, $map, config('trip.ttl.day') * self::MAX_CACHE_DAY);
    }
}
